//
//  BaseViewController.swift
//  WeiBo
//
//  Created by LTX on 2016/11/1.
//  Copyright © 2016年 LTX. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    // 访客视图
    lazy var guestView : VisitorView = VisitorView.visitView()
    
    
    
    //是否登录
    var isLogin: Bool = UserAccountViewModel.shareIntance.isLogin
    
    //重写loadView方法
    override func loadView() {
        
        isLogin ? super.loadView() : setupVisitorView()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setNavgationItem()
    }


}

// MARK:- 设置UI
extension BaseViewController{

    //显示访客视图
   fileprivate func setupVisitorView() -> Void {
        view = guestView
    
    guestView.registerBtn.addTarget(self, action: #selector(register), for: .touchUpInside)
    guestView.loginBtn.addTarget(self, action: #selector(login), for: .touchUpInside)
    
    }
    
    // MARK:- 设置导航栏按钮
  fileprivate  func setNavgationItem() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(register))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(login))
    }
    
}

// MARK:- 事件监听
extension BaseViewController {
    //注册点击
    func register() {
        print("点击了注册")
    }
    
    //登录点击
    func login()  {
        print("点击了登录")
        
        let OAtuh = OAuthViewController()
        
        let OAuthNav = UINavigationController(rootViewController: OAtuh)
        
        present(OAuthNav, animated: true, completion: nil)
        
        
        
        
        
    }

}


